<template>
  <div class="home">
    <el-menu
      :default-active="$route.path"
      :router="true"
      class="el-menu-demo"
      mode="horizontal"
      background-color="#ab1f2a"
      text-color="#fff"
      active-text-color="#ffd04b"
      @select="handleSelect"
    >
      <img src="../assets/rjxy.png" alt="山大标志" id="logo" />
      <div id="contain">
        <el-menu-item index="/"> 首页 </el-menu-item>
        <el-menu-item index="/job_dash"> 招聘信息 </el-menu-item>
        <el-menu-item index="/dash"> 毕业去向 </el-menu-item>
      </div>
    </el-menu>
    <router-view />
    <Footer />
  </div>
</template>

<script>
import Footer from "./Footer.vue";

export default {
  name: "Home",
  components: {
    Footer,
  },
  data() {
    return {
      activeIndex: "/",
    };
  },
  created() {
    this.setCurrentRoute();
  },
  watch: {
    $route() {
      this.setCurrentRoute();
    },
  },
  methods: {
    setCurrentRoute() {
      this.activeIndex = this.$route.path; //关键   通过他就可以监听到当前路由状态并激活当前菜单
      console.log(this.activeIndex);
    },
    handleSelect(key, keyPath) {
      console.log(this.activeIndex);
      console.log(key, keyPath);
    },
  },
};
</script>
<style scoped>
.router-link-active {
  text-decoration: none;
  color: #fff;
}
a {
  text-decoration: none;
  color: #fff;
  font-size: 0.8em;
}

.el-menu-demo {
  width: 100%;
  display: flex;
  display: -webkit-flex; /* Safari */
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
}
.el-menu-item {
  font-size: 1.6em;
}
#logo {
  margin: 1em 0;
}
#contain {
  display: -webkit-flex; /* Safari */
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
}
</style>
<style>
.el-submenu__title {
  font-size: 1.6em;
}

.el-menu-item.is-active {
  font-weight: bold !important;
}
</style>
